<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body {
				background: #F7F8FA;
				/*overflow: auto;
				-webkit-overflow-scrolling:touch;
				*/
			}
			
			.index_list{ padding: 15px;}
			.index_list li{ box-shadow: 0 5px 20px rgba(0,0,0,0.08); padding: 33px 23px; position: relative; display:block; background-color: #fff; border-radius: 5px; margin-bottom: 15px; overflow: hidden;}
			.index_list h4{ display:block; font-size: 20px; color: #333; line-height: 25px;}
			.index_list p{ font-size: 12px; color: #9f9f9f; line-height: 25px;}
			.index_list img{ position: absolute; right: 10px; top: 50%; margin-top: -50px; height: 100px;}
			.display-none { display:none !important; }
		</style>
	</head>
	<body>
		<!--列表start-->
		<div class="index_list">
			<ul>
				<li tapmode="lipress" onclick="addgoods();">
					<h4>发布货源</h4>
					<p>在线匹配车主为我发货</p>
					<img src="../../image/img_01.png" alt="" />
				</li>
				<li tapmode="lipress" onclick="openNavWin('#ddd','searchgoods_win','../goods/searchgoods_frm.html','查找货源',false,false,true,[{iconPath: 'widget://image/search.png'}],{});">
	
					<h4>查找货源</h4>
					<p>查找附近货源，接单赚钱</p>
					<img src="../../image/img_02.png" alt="" />
				</li>
				<li tapmode="lipress" id="lianbao" class="display-none" onclick="opWin('insure_win','../insure/insure_win.html',true,{},false);">
					<h4>车辆联保</h4>
					<p>接单出货全能保，出行更安心</p>
					<img src="../../image/img_03.png" alt="" />
				</li>
			</ul>
		</div>
		<!--列表end-->
		
	</body>
	<script type="text/javascript" src="../../script/api.js" ></script>
	<script type="text/javascript" src="../../script/app.js" ></script>
	<script type="text/javascript">
		var rong;
		apiready = function() {
			rong = api.require('rongCloud2');
			//NVTabBar = api.require('NVTabBar');
			api.parseTapmode();
			getJsonFromAPI();
			var transformarr = [];
			for(var i=1; i<24; i++)
			{
				var index = i < 10 ? '0'+i : i;
				transformarr.push('widget://image/UIPullRefreshImg/pull_end_image_frame_'+index+'.png');
			}
			api.setCustomRefreshHeaderInfo({
				bgColor : '#F7F8FA',
				image : {
					pull : 'widget://image/UIPullRefreshImg/pull.png',
					transform : transformarr,
					load : transformarr
				}
			}, function(ret, err) {
				getJsonFromAPI();
				setTimeout(function() {
					api.refreshHeaderLoadDone();
				}, 3000)
			});
			api.addEventListener({
				name : 'refreshindex'
			}, function(ret, err) {
				getJsonFromAPI();
				
			});
			api.addEventListener({
				name : 'reloadpage'
			}, function(ret, err) {
				getJsonFromAPI();
				
			});
			api.addEventListener({
				name:'offline'
			}, function(ret, err){        
				opNonetwork();
			});
		}
		
		function addgoods() {
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					
					if(userinfo.status!=1){
						tipbox(userinfo.status);
						return;
					}
					openNavWin('#ddd','addgoods_win','../goods/addgoods_frm.html','发布货源',false,false,true,[],{});
				}
			});
			
			
		}
		function reloadUnreadCount() {
			//重载未读数
			
			rong.getTotalUnreadCount(function(ret, err) {
				if(ret)
				{
					getJsonFromAPIextra(ret.result);
					
				}	
			});
		}
		function getJsonFromAPIextra(msgcount) {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);

					api.ajax({
						url: ApiUrl + '/v1/homes/',
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						if (ret) {
							var iindex = 2;
							var noreadsysmsg = parseInt(ret.noreadsysmsg) + parseInt(msgcount);
							api.execScript({
								name: 'root',
								script: 'changeBadeg('+noreadsysmsg+');'
							});
							//if(noreadsysmsg > 0)
							//{
								//NVTabBar.setBadge({
									//index: iindex,
									//badge: ''
								//});
							//}
							//else
							//{
								//NVTabBar.setBadge({
									//index: iindex,
									//badge: '0'
								//});
							//}
						}
					});
				}
			});
		}
		function getJsonFromAPI() {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);

					api.ajax({
						url: ApiUrl + '/v1/homes/',
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						api.refreshHeaderLoadDone();
						if (ret) {
							if(ret.ishidden == 0) {
								$api.removeCls($api.byId('lianbao'),'display-none');
							}
							console.log(JSON.stringify(ret));
							var iindex = 2;
							var noreadsysmsg = parseInt(ret.noreadsysmsg);
							//alert(noreadsysmsg);
							setTimeout(function(){
								api.execScript({
									name: 'root',
									script: 'changeBadeg('+noreadsysmsg+');'
								});
							}, 1000);
							//if(noreadsysmsg > 0)
							//{
								//NVTabBar.setBadge({
									//index: iindex,
									//badge: ''
								//});
							//}
							setTimeout(function(){
								api.sendEvent({
									name : 'changeredpoint',
									extra : {
										msgjson : {sysnoreadmsg:ret.sysnoreadmsg,friendnoreadmsg:ret.friendnoreadmsg}
									}
								});
							}, 0);
							
							userinfo.status = ret.status;
							userinfo.ishidden = ret.ishidden;
							api.setPrefs({
								key: 'user_info',
								value: userinfo
							}, function(ret, err) {
								if(ret)
								{
									api.sendEvent({
										name : 'updateuser',
										extra : {
											userjson : userinfo
										}
									});
								}
							});
							api.removeLaunchView({
								animation : {
									type : 'fade',
									duration : 500
								}
							});
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								console.log(JSON.stringify(err));
								toast('网络异常');
							}
						}
					});
				}
			});
		}
	</script>
</html>